﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：编码规则管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var companyId = '';
    var page = {
        init: function () {
            page.inittree();
            page.bind();
            page.initGrid();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });


            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑编码规则',
                        url: config.webportal_server + 'pages/system/coderule/form.html?access_token=' + config.getToken().access_token + '&companyId=' + companyId,
                        width: 900,
                        height: 379,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });

        },
        inittree: function () {
            $('#companyTree').lrtree({
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                param: {parentId: '0'},
                nodeClick: page.treeNodeClick
            });
            $('#companyTree').lrtreeSet('checkFirst');
        },
        treeNodeClick: function (item) {
            companyId = item.id;
            $('#titleinfo').text(item.text);
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'coderules/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '编号', name: 'code', width: 60, align: 'left'},
                    {label: '名称', name: 'name', width: 80, align: 'left'},
                    {
                        label: '一级', name: 'level1', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '二级', name: 'level2', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '三级', name: 'level3', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '四级', name: 'level4', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '五级', name: 'level5', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '六级', name: 'level6', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '七级', name: 'level7', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '八级', name: 'level8', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '九级', name: 'level9', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十级', name: 'level10', width: 40, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十一级', name: 'level11', width: 60, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十二级', name: 'level12', width: 60, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十三级', name: 'level13', width: 60, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十四级', name: 'level14', width: 60, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '十五级', name: 'level15', width: 60, align: 'center',
                        formatter: function (cellvalue) {
                            return cellvalue > 1 ? cellvalue : "";
                        }
                    },
                    {
                        label: '更新时间', name: 'updateTime', width: 140, align: 'center',
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                    {label: "描述", name: "remark", index: "remark", width: 60, align: "left"}

                ],
                isPage: true,
                reloadSelected: true,
                isTree: false,
                mainId: 'id'
            });
        },
        search: function (param) {
            param = param || {};
            param.companyId = companyId;

            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


